using UnityEngine;
using System.Collections;

public class MenuControl : MonoBehaviour {
	
	#region Attributes
	
	
	private bool paused = false;
	[HideInInspector]
	public bool dead = false;
	[HideInInspector]
    public bool pause = false;

	#endregion
	
	#region Methods
	#endregion
	
	#region Unity Methods
	void Start () {
		
		dead = false;	
		pause = false;
		paused = false;
		
		InitPauseMenu();
		InitDeatheMenu();
		
	}
	
	void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape)&& !dead)
        {
            this.pause = !this.pause;
            this.DoPause();
			
			DrawPauseMenu(paused);
        }
		
		if(dead)
		{
			this.pause = true;
            this.DoPause();
			
			DrawDeathMenu(paused);
			
		}
	}

    
	#endregion
	
	#region Methods
	public void DoPause()
    {
        if (this.pause)
            paused = GameControl.PauseGame(paused);
        else
            paused = GameControl.UnpauseGame(paused);
    }
	
	public void DrawPauseMenu(bool pause)
	{
		transform.Find("PauseMenu").guiTexture.enabled = pause;
		transform.Find("ContinueButton").guiTexture.enabled = pause;
		transform.Find("RestartButton").guiTexture.enabled = pause;
		transform.Find("MainButton").guiTexture.enabled = pause;
		
	}
	
	private void InitPauseMenu()
	{
		transform.Find("PauseMenu").guiTexture.enabled = false;
		transform.Find("ContinueButton").guiTexture.enabled = false;
		transform.Find("RestartButton").guiTexture.enabled = false;
		transform.Find("MainButton").guiTexture.enabled = false;		
	}
	
	public void DrawDeathMenu(bool death)
	{
		transform.Find("DeathMenu").guiTexture.enabled = death;
		transform.Find("RetryButton").guiTexture.enabled = death;
		transform.Find("MainDeathButton").guiTexture.enabled = death;
		
	}
	
	private void InitDeatheMenu()
	{
		transform.Find("DeathMenu").guiTexture.enabled = false;
		transform.Find("RetryButton").guiTexture.enabled = false;
		transform.Find("MainDeathButton").guiTexture.enabled = false;		
	}
	public void RestartScene(){
		
		dead = false;
		Application.LoadLevel(Application.loadedLevelName);
		this.pause = !this.pause;
        this.DoPause();
		
	}
	
	#endregion
}
